package com.icinfo.cloud.provider.punish.common.seal.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.common.seal.dto.BindSealPageDto;
import com.icinfo.cloud.provider.punish.common.seal.dto.FileSealInfoQueryDto;
import com.icinfo.cloud.provider.punish.common.seal.service.IFileSealProvinceUnifiedService;
import com.icinfo.cloud.provider.punish.common.seal.service.IFileSealService;
import com.icinfo.cloud.provider.punish.common.seal.vo.BindSealVo;
import com.icinfo.framework.common.web.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 描述：文件签章前端控制器
 *
 * @author XiangYuYu
 * @date 2021/11/8 7:17 PM
 */

@RestController
@RefreshScope
@RequestMapping("/punish/seal")
public class FileSealController {

    @Resource
    private IFileSealService iFileSealService;
    @Resource
    private IFileSealProvinceUnifiedService fileSealProvinceUnifiedService;

    /**
     * 【V1.0.0】描述：签章并获取签章后的文件
     *
     * @param queryDto {@link FileSealInfoQueryDto}
     * @return Result 签章后的信息
     * @author xiangyuyu
     * @date 2022-03-02 09:09
     */
    @ApiOperation(value = "签章并获取签章后的文件", httpMethod = "POST")
    @PostMapping("/getFileAfterSeal")
    public Result getFileAfterSeal(@Validated FileSealInfoQueryDto queryDto) {
        Map<String, Object> resultMap = fileSealProvinceUnifiedService.getFileAfterSeal(queryDto);
        Object errorMsgObj = resultMap.get("errorMsg");
        if (ObjectUtils.isEmpty(errorMsgObj)) {
            return Result.success("获取成功", resultMap.get("fileBytes"));
        } else {
            return Result.error(Constant.SEAL_ERROR_MESSAGE);
        }
    }

    /**
     * 【V1.0.0】描述：签章并获取签章后的文件
     *
     * @param queryDto {@link FileSealInfoQueryDto}
     * @return Result 签章后的信息
     * @author xiangyuyu
     * @date 2022-03-02 09:09
     */
    @ApiOperation(value = "签章并获取签章后的文件BASE64", httpMethod = "POST")
    @PostMapping("/getFileAfterSealString")
    public Result getFileAfterSealString(@Validated @RequestBody FileSealInfoQueryDto queryDto) {
        String sealUrl = fileSealProvinceUnifiedService.dealFileSeal(queryDto);
        return Result.success("获取成功", sealUrl);
    }

    /**
     * 【V1.3.5】描述：分页获取傲雄签章信息
     *
     * @param dto {@link BindSealPageDto}
     * @return Result 签章信息
     * @author xiangyuyu
     * @date 2022-03-02 09:09
     */
    @PostMapping("/page")
    public Result<PageResponse<BindSealVo>> getBindSealPage(@Validated @RequestBody BindSealPageDto dto) {
        return Result.success("获取成功", fileSealProvinceUnifiedService.getBindSealPage(dto));
    }
}
